<?php
defined('_JEXEC') or die('Restricted access');
require_once(JPATH_COMPONENT.DS.'persistencia'.DS.'DAOComment.php');
require_once(JPATH_COMPONENT.DS.'persistencia'.DS.'tables'.DS.'comentario.php');
require_once(JPATH_COMPONENT.DS.'dominio'.DS.'DTOFactory.php');

class JDAOComment implements DAOComment{

	public function saveComment($comment){
		$factoria=DTOFactory::getInstance();
		$row=$factoria->fromDTOEventComment2EventCommentTable($comment);
		if(!$row->store()){
	        JError::raiseError(500, $row->getError() );
	    }
	}

	public function readComments($idEvento){
		$listaComentarios = $this->multipleObjectQuery("SELECT * FROM #__comentario WHERE idEvento = ".$idEvento);
		// la factoria la convierte en una lista de DTOEvent
		$factoria=DTOFactory::getInstance();
		return $factoria->fromObjectList2DTOComentarioList($listaComentarios);
	}
	private function singleObjectQuery($query){
		$db =& JFactory::getDBO();
		$db->setQuery( $query );
		$row = $db->loadObject();
		if ($db->getErrorNum()) {
			echo $db->stderr();
			return false;
		}
		return $row;
	}
	private function multipleObjectQuery($query){
		$db =& JFactory::getDBO();
		$db->setQuery($query);
		return $db->loadObjectList();
	}
	private function multipleRowQuery($query){
		$db =& JFactory::getDBO();
		$db->setQuery($query);
		return $db->loadAssocList();
	}
	private function singleAssociativeQuery($query){
		$db =& JFactory::getDBO();
		$db->setQuery( $query );
		$row = $db->loadAssoc();
		if ($db->getErrorNum()) {
			echo $db->stderr();
			return false;
		}
		return $row;
	}
}

?>